<!doctype html>



  


<html class="theme-next mist use-motion">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/vendors/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/vendors/font-awesome/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.0.1" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Java web," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.0.1" />






<meta name="description" content="说明：Mybatis配置使用。">
<meta name="keywords" content="Java web">
<meta property="og:type" content="article">
<meta property="og:title" content="Mybatis">
<meta property="og:url" content="http://bebetter.site/2017/01/12/Software/Java Web/Mybatis/index.html">
<meta property="og:site_name" content="gatewayzy">
<meta property="og:description" content="说明：Mybatis配置使用。">
<meta property="og:updated_time" content="2017-01-12T05:58:56.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Mybatis">
<meta name="twitter:description" content="说明：Mybatis配置使用。">



<script type="text/javascript" id="hexo.configuration">
  var NexT = window.NexT || {};
  var CONFIG = {
    scheme: 'Mist',
    sidebar: {"position":"right","display":"always"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: 0,
      author: '博主'
    }
  };
</script>




  <link rel="canonical" href="http://bebetter.site/2017/01/12/Software/Java Web/Mybatis/"/>

  <title> Mybatis | gatewayzy </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  










  
  
    
  

  <div class="container one-collumn sidebar-position-right page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">gatewayzy</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">blog of gatewayzy</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
    </ul>
  

  
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                Mybatis
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">发表于</span>
            <time itemprop="dateCreated" datetime="2017-01-12T13:58:13+08:00" content="2017-01-12">
              2017-01-12
            </time>
          </span>

          
            <span class="post-category" >
              &nbsp; | &nbsp;
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
              
                <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
                  <a href="/categories/Softwares/" itemprop="url" rel="index">
                    <span itemprop="name">Softwares</span>
                  </a>
                </span>

                
                

              
            </span>
          

          
            
          

          

          
          

          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <p><strong>说明：</strong>Mybatis配置使用。<br><a id="more"></a></p>
<hr>
<p>参考文章：</p>
<h2 id="Mybatis介绍"><a href="#Mybatis介绍" class="headerlink" title="Mybatis介绍"></a>Mybatis介绍</h2><hr>
<ul>
<li>iBatis迁移到Google Code 旗下，改名为Mybatis 3.x。</li>
</ul>
<h2 id="使用"><a href="#使用" class="headerlink" title="使用"></a>使用</h2><hr>
<h3 id="插入数据后的主键"><a href="#插入数据后的主键" class="headerlink" title="插入数据后的主键"></a>插入数据后的主键</h3><hr>
<ul>
<li>设置useGeneratedKeys=”true” keyProperty=”feedbackId”，keyProperty如果是数据表中字段名，无法获取，应设置成对象的名称。</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div></pre></td><td class="code"><pre><div class="line">&lt;resultMap type=&quot;com.usercenter.pojo.FeedbackPo&quot; id=&quot;feedbackMap&quot;&gt;</div><div class="line">	&lt;id property=&quot;feedbackId&quot; column=&quot;id&quot; /&gt;</div><div class="line">	&lt;result property=&quot;errorUrl&quot; column=&quot;error_url&quot; /&gt;</div><div class="line">	&lt;result property=&quot;title&quot; column=&quot;title&quot; /&gt;</div><div class="line">	&lt;result property=&quot;content&quot; column=&quot;content&quot; /&gt;</div><div class="line">	&lt;result property=&quot;feedbackSource&quot; column=&quot;feedback_source&quot; /&gt;</div><div class="line">	&lt;result property=&quot;anonymous&quot; column=&quot;anonymous&quot; /&gt;</div><div class="line">	&lt;result property=&quot;userExtendId&quot; column=&quot;user_extend_id&quot; /&gt;</div><div class="line">	&lt;result property=&quot;ip&quot; column=&quot;ip&quot; /&gt;</div><div class="line">	&lt;result property=&quot;feedbackTime&quot; column=&quot;feedback_time&quot; /&gt;</div><div class="line">	&lt;result property=&quot;count&quot; column=&quot;count&quot; /&gt;</div><div class="line">	&lt;result property=&quot;subsysName&quot; column=&quot;subsys_name&quot; /&gt;</div><div class="line">	&lt;result property=&quot;sent&quot; column=&quot;sent&quot; /&gt;</div><div class="line">	&lt;result property=&quot;solved&quot; column=&quot;solved&quot; /&gt;</div><div class="line">	&lt;result property=&quot;solveDever&quot; column=&quot;solve_dever&quot; /&gt;</div><div class="line">	&lt;result property=&quot;solveTime&quot; column=&quot;solve_time&quot; /&gt;</div><div class="line">	&lt;result property=&quot;category&quot; column=&quot;category&quot; /&gt;</div><div class="line">	&lt;result property=&quot;solution&quot; column=&quot;solution&quot; /&gt;</div><div class="line">	&lt;result property=&quot;reply&quot; column=&quot;reply&quot; /&gt;</div><div class="line">	&lt;result property=&quot;comment&quot; column=&quot;comment&quot; /&gt;</div><div class="line">&lt;/resultMap&gt;</div><div class="line"></div><div class="line">&lt;insert id=&quot;insertOne&quot; parameterType=&quot;java.util.HashMap&quot;</div><div class="line">	useGeneratedKeys=&quot;true&quot; keyProperty=&quot;feedbackId&quot; flushCache=&quot;true&quot;&gt;</div><div class="line">	insert into feedback (error_url,title,content,feedback_source</div><div class="line">	&lt;if test=&quot;anonymous !=null&quot;&gt;,anonymous&lt;/if&gt;</div><div class="line">	&lt;if test=&quot;userExtendId !=null&quot;&gt;,user_extend_id&lt;/if&gt;</div><div class="line">	&lt;if test=&quot;ip !=null&quot;&gt;,ip&lt;/if&gt;</div><div class="line">	&lt;if test=&quot;feedbackTime !=null&quot;&gt;,feedback_time&lt;/if&gt;</div><div class="line">	&lt;if test=&quot;count !=null&quot;&gt;,count&lt;/if&gt;</div><div class="line">	&lt;if test=&quot;subsysName !=null&quot;&gt;,subsys_name&lt;/if&gt;</div><div class="line">	&lt;if test=&quot;sent !=null&quot;&gt;,sent&lt;/if&gt;</div><div class="line">	&lt;if test=&quot;solved !=null&quot;&gt;,solved&lt;/if&gt;</div><div class="line">	&lt;if test=&quot;solveDever !=null&quot;&gt;,solve_dever&lt;/if&gt;</div><div class="line">	&lt;if test=&quot;solveTime !=null&quot;&gt;,solve_time&lt;/if&gt;</div><div class="line">	&lt;if test=&quot;category !=null&quot;&gt;,category&lt;/if&gt;</div><div class="line">	&lt;if test=&quot;solution !=null&quot;&gt;,solution&lt;/if&gt;</div><div class="line">	&lt;if test=&quot;reply !=null&quot;&gt;,reply&lt;/if&gt;</div><div class="line">	&lt;if test=&quot;comment !=null&quot;&gt;,comment&lt;/if&gt;</div><div class="line">	)</div><div class="line">	values(#&#123;errorUrl&#125;,#&#123;title&#125;,#&#123;content&#125;,#&#123;feedbackSource&#125;</div><div class="line">	&lt;if test=&quot;anonymous !=null&quot;&gt;,#&#123;anonymous&#125;&lt;/if&gt;</div><div class="line">	&lt;if test=&quot;userExtendId !=null&quot;&gt;,#&#123;userExtendId&#125;&lt;/if&gt;</div><div class="line">	&lt;if test=&quot;ip !=null&quot;&gt;,#&#123;ip&#125;&lt;/if&gt;</div><div class="line">	&lt;if test=&quot;feedbackTime !=null&quot;&gt;,#&#123;feedbackTime&#125;&lt;/if&gt;</div><div class="line">	&lt;if test=&quot;count !=null&quot;&gt;,#&#123;count&#125;&lt;/if&gt;</div><div class="line">	&lt;if test=&quot;subsysName !=null&quot;&gt;,#&#123;subsysName&#125;&lt;/if&gt;</div><div class="line">	&lt;if test=&quot;sent !=null&quot;&gt;,#&#123;sent&#125;&lt;/if&gt;</div><div class="line">	&lt;if test=&quot;solved !=null&quot;&gt;,#&#123;solved&#125;&lt;/if&gt;</div><div class="line">	&lt;if test=&quot;solveDever !=null&quot;&gt;,#&#123;solveDever&#125;&lt;/if&gt;</div><div class="line">	&lt;if test=&quot;solveTime !=null&quot;&gt;,#&#123;solveTime&#125;&lt;/if&gt;</div><div class="line">	&lt;if test=&quot;category !=null&quot;&gt;,#&#123;category&#125;&lt;/if&gt;</div><div class="line">	&lt;if test=&quot;solution !=null&quot;&gt;,#&#123;solution&#125;&lt;/if&gt;</div><div class="line">	&lt;if test=&quot;reply !=null&quot;&gt;,#&#123;reply&#125;&lt;/if&gt;</div><div class="line">	&lt;if test=&quot;comment !=null&quot;&gt;,#&#123;comment&#125;&lt;/if&gt;</div><div class="line">	)</div><div class="line">&lt;/insert&gt;</div></pre></td></tr></table></figure>
<h3 id="Xml使用foreach"><a href="#Xml使用foreach" class="headerlink" title="Xml使用foreach"></a>Xml使用foreach</h3><hr>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div></pre></td><td class="code"><pre><div class="line">&lt;select id=&quot;selectTopicsByIds&quot; parameterType=&quot;list&quot; resultType=&quot;com.tcm.dal.qaos.po.TopicPo&quot;&gt;</div><div class="line">select  topic_id as topicId,</div><div class="line">        topic_title as topicTitle,</div><div class="line">        left(topic_time,16) as topicTime,</div><div class="line">        reply_cnt as  replyCnt,</div><div class="line">        support_cnt as supportCnt,</div><div class="line">        oppose_cnt as opposeCnt,</div><div class="line">        tags</div><div class="line">from qa_topic</div><div class="line">where topic_id in</div><div class="line">  &lt;foreach item=&quot;item&quot; index=&quot;index&quot; collection=&quot;list&quot; </div><div class="line">             open=&quot;(&quot; separator=&quot;,&quot; close=&quot;)&quot;&gt; </div><div class="line">            #&#123;item&#125; </div><div class="line">     &lt;/foreach&gt; </div><div class="line">&lt;/select&gt;</div></pre></td></tr></table></figure>
<h2 id="使用spring管理Mybatis"><a href="#使用spring管理Mybatis" class="headerlink" title="使用spring管理Mybatis"></a>使用spring管理Mybatis</h2><hr>
<ul>
<li>web.xml中配置spring拦截器</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div></pre></td><td class="code"><pre><div class="line">&lt;!-- 派遣器配置 --&gt;</div><div class="line"> 	&lt;servlet&gt;</div><div class="line">  		&lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;</div><div class="line">  	  	&lt;servlet-class&gt;</div><div class="line">  	  	   org.springframework.web.servlet.DispatcherServlet</div><div class="line">  	 	&lt;/servlet-class&gt;</div><div class="line">  	 	&lt;init-param&gt;</div><div class="line">		&lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;</div><div class="line">		&lt;param-value&gt;/WEB-INF/tcm-servlet.xml&lt;/param-value&gt;</div><div class="line">  	&lt;/init-param&gt;</div><div class="line">  	  	&lt;load-on-startup&gt;1&lt;/load-on-startup&gt;</div><div class="line"> 	&lt;/servlet&gt;</div><div class="line">	&lt;servlet-mapping&gt;</div><div class="line"> 	    &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;</div><div class="line">	    &lt;url-pattern&gt;/&lt;/url-pattern&gt;</div><div class="line">&lt;/servlet-mapping&gt;</div></pre></td></tr></table></figure>
<ul>
<li>/WEB-INF/tcm-servlet.xml中导入bean文件</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">&lt;!-- 导入bean 配置文件 --&gt;</div><div class="line">&lt;import resource=&quot;./config/beansContext.xml&quot; /&gt;</div></pre></td></tr></table></figure>
<ul>
<li>beansContext.xml中配置mybatis的bean</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div></pre></td><td class="code"><pre><div class="line">&lt;!-- 配置mybatis固定的写法 --&gt;</div><div class="line">&lt;bean id=&quot;sqlSessionFactory&quot; class=&quot;org.mybatis.spring.SqlSessionFactoryBean&quot;&gt;</div><div class="line">	&lt;property name=&quot;dataSource&quot; ref=&quot;dataSource&quot; /&gt;</div><div class="line">	&lt;property name=&quot;configLocation&quot; value=&quot;/WEB-INF/mybatis/sqlMapConfig.xml&quot; /&gt;</div><div class="line">&lt;/bean&gt;</div><div class="line">&lt;bean id=&quot;sqlSession&quot; class=&quot;org.mybatis.spring.SqlSessionTemplate&quot;&gt;</div><div class="line">	&lt;constructor-arg index=&quot;0&quot; ref=&quot;sqlSessionFactory&quot;&gt;&lt;/constructor-arg&gt;</div><div class="line">&lt;/bean&gt;</div><div class="line">&lt;!-- data OR mapping interface --&gt;</div><div class="line">&lt;bean class=&quot;org.mybatis.spring.mapper.MapperScannerConfigurer&quot;&gt;</div><div class="line">	&lt;property name=&quot;basePackage&quot; value=&quot;com.tcm.module.properties&quot; /&gt;</div><div class="line">&lt;/bean&gt;</div></pre></td></tr></table></figure>
<ul>
<li>/WEB-INF/mybatis/sqlMapConfig.xml中配置mapper文件目录和别名等</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line">&lt;typeAliases&gt;</div><div class="line">	&lt;!-- &lt;typeAlias type=&quot;com.bingu.dal.AssociationRulePo&quot; alias=&quot;AssociationRulePo&quot; /&gt;  --&gt;</div><div class="line">	&lt;typeAlias type=&quot;com.usercenter.pojo.VisitorsInfoPo&quot; alias=&quot;VisitorsInfoPo&quot; /&gt;</div><div class="line">&lt;/typeAliases&gt;</div><div class="line"></div><div class="line">&lt;mappers&gt;</div><div class="line">	&lt;!-- 使用相对于类路径的资源引用,到web应用的resources/路径下对应的xml映射文件 --&gt;</div><div class="line">	&lt;mapper resource=&quot;dao/ConstsDao.xml&quot; /&gt;</div><div class="line">	&lt;mapper resource=&quot;dao/VisitorsInfoDao.xml&quot; /&gt;</div><div class="line">&lt;/mappers&gt;</div></pre></td></tr></table></figure>
<ul>
<li>ConstsDao.xml中配置sql</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div></pre></td><td class="code"><pre><div class="line">&lt;mapper namespace=&quot;dao.constsDao&quot;&gt;</div><div class="line">	&lt;cache type=&quot;org.mybatis.caches.ehcache.EhcacheCache&quot; /&gt;</div><div class="line">	&lt;resultMap type=&quot;constsPo&quot; id=&quot;constsMap&quot;&gt;</div><div class="line">		&lt;id property=&quot;id&quot; column=&quot;id&quot; /&gt;</div><div class="line">		&lt;result property=&quot;internetValue&quot; column=&quot;internet_value&quot; /&gt;</div><div class="line">		&lt;result property=&quot;intranetValue&quot; column=&quot;intranet_value&quot; /&gt;</div><div class="line">		&lt;result property=&quot;comment&quot; column=&quot;comment&quot; /&gt;</div><div class="line">	&lt;/resultMap&gt;</div><div class="line"></div><div class="line">	&lt;select id=&quot;selectByName&quot; parameterType=&quot;String&quot; resultMap=&quot;constsMap&quot;&gt;</div><div class="line">		select * from const</div><div class="line">		where name = #&#123;name&#125;</div><div class="line">	&lt;/select&gt;</div><div class="line">&lt;/mapper&gt;</div></pre></td></tr></table></figure>
<ul>
<li>dao代码通过命名空间和参数传递访问数据库</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div></pre></td><td class="code"><pre><div class="line">@Repository</div><div class="line">public class ConstsDaoImpl implements ConstsDao&#123;</div><div class="line">	private SqlSession sqlSession;</div><div class="line"></div><div class="line">	@Resource</div><div class="line">	public void setSqlSession(SqlSession sqlSession) &#123;</div><div class="line">		this.sqlSession = sqlSession;</div><div class="line">	&#125;</div><div class="line"></div><div class="line">	@Override</div><div class="line">	public ConstsPo selectByName(String name) &#123;</div><div class="line">		return sqlSession.selectOne(&quot;dao.constsDao.selectByName&quot;, name);</div><div class="line">	&#125;</div><div class="line"></div><div class="line">	</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<ul>
<li>service层使用dao进行业务封装</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div></pre></td><td class="code"><pre><div class="line">@Service</div><div class="line">public class ConstsServiceImpl implements ConstsService &#123;</div><div class="line">	@Resource</div><div class="line">	private ConstsDaoImpl ConstsDaoImpl;</div><div class="line"></div><div class="line">	@Override</div><div class="line">	public boolean isLinux() &#123;</div><div class="line">		Properties properties = System.getProperties();</div><div class="line">		String os = properties.getProperty(&quot;os.name&quot;);</div><div class="line">		if (os.startsWith(&quot;win&quot;) || os.startsWith(&quot;Win&quot;)) &#123;</div><div class="line">			return false;</div><div class="line">		&#125;</div><div class="line">		return true;</div><div class="line">	&#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h2 id="使用eclipse的mybatis插件"><a href="#使用eclipse的mybatis插件" class="headerlink" title="使用eclipse的mybatis插件"></a>使用eclipse的mybatis插件</h2><hr>
<ul>
<li>使用框架插件，在项目中添加mybatis。一般先建立maven项目，拥有完整的文件目录，如src/main/resources等，新建ORM框架，可能要配置包名为main，或者补全丢失的目录。</li>
</ul>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Java-web/" rel="tag">#Java web</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/01/12/Software/Automated build tools 自动化构建工具/Maven/" rel="next" title="Maven">
                <i class="fa fa-chevron-left"></i> Maven
              </a>
            
          </div>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/01/12/Software/Java Web/Nginx/" rel="prev" title="Nginx">
                Nginx <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    


  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel ">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/statics/images/avatar.png"
               alt="gatewayzy" />
          <p class="site-author-name" itemprop="name">gatewayzy</p>
          <p class="site-description motion-element" itemprop="description">blog website with hexo and github pages</p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">70</span>
              <span class="site-state-item-name">日志</span>
            </a>
          </div>

          
            <div class="site-state-item site-state-categories">
              <a href="/categories">
                <span class="site-state-item-count">10</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags">
                <span class="site-state-item-count">38</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
        </div>

        
        

        
        
          <div class="links-of-blogroll motion-element links-of-blogroll-inline">
            <div class="links-of-blogroll-title">
              <i class="fa  fa-fw fa-globe"></i>
              友情链接
            </div>
            <ul class="links-of-blogroll-list">
              
                <li class="links-of-blogroll-item">
                  <a href="https://github.com/gatewayzy" title="Github-gatewayzy" target="_blank">Github-gatewayzy</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://google.com/" title="Goolge" target="_blank">Goolge</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://wiki.jikexueyuan.com/" title="Wiki-jike" target="_blank">Wiki-jike</a>
                </li>
              
            </ul>
          </div>
        

      </section>

      
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">
            
              
            
            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#Mybatis介绍"><span class="nav-number">1.</span> <span class="nav-text">Mybatis介绍</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#使用"><span class="nav-number">2.</span> <span class="nav-text">使用</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#插入数据后的主键"><span class="nav-number">2.1.</span> <span class="nav-text">插入数据后的主键</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Xml使用foreach"><span class="nav-number">2.2.</span> <span class="nav-text">Xml使用foreach</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#使用spring管理Mybatis"><span class="nav-number">3.</span> <span class="nav-text">使用spring管理Mybatis</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#使用eclipse的mybatis插件"><span class="nav-number">4.</span> <span class="nav-text">使用eclipse的mybatis插件</span></a></li></ol></div>
            
          </div>
        </section>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">gatewayzy</span>
</div>

<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Mist
  </a>
</div>

        

        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/vendors/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/vendors/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/vendors/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/vendors/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/vendors/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/vendors/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.0.1"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.0.1"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.0.1"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.0.1"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.0.1"></script>



  



  




  
  

  
  <script type="text/x-mathjax-config">
    MathJax.Hub.Config({
      tex2jax: {
        inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
        processEscapes: true,
        skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
      }
    });
  </script>

  <script type="text/x-mathjax-config">
    MathJax.Hub.Queue(function() {
      var all = MathJax.Hub.getAllJax(), i;
      for (i=0; i < all.length; i += 1) {
        all[i].SourceElement().parentNode.className += ' has-jax';
      }
    });
  </script>
  <script type="text/javascript" src="//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>



  

  
<script type="text/javascript" async src="//push.zhanzhang.baidu.com/push.js">
</script>


</body>
</html>
